package com.quasar.hpatient.view.adapter;

import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.TemperatureTableItem;
import com.quasar.hpatient.utils.Spanny;
import com.vise.log.ViseLog;

import java.math.BigDecimal;
import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/12/13 0013
 * View:
 */

public class DailyLinAdapter extends BaseMultiItemQuickAdapter<TemperatureTableItem, BaseViewHolder> {

    public DailyLinAdapter(List<TemperatureTableItem> data) {
        super(data);
        //体温
        addItemType(TemperatureTableItem.ONE, R.layout.widget_temperature_medicine);
        //血压
        addItemType(TemperatureTableItem.TWO, R.layout.widget_blood_head);
        addItemType(TemperatureTableItem.THREE, R.layout.widget_blood_pressure);
        //血糖
        addItemType(TemperatureTableItem.FOUR, R.layout.widget_test_show);

        //出入量
        addItemType(TemperatureTableItem.FIVE, R.layout.widget_test_show);
        addItemType(TemperatureTableItem.SIX, R.layout.widget_test_show);
        addItemType(TemperatureTableItem.SERVER, R.layout.widget_test_show);

    }

    @Override
    protected void convert(BaseViewHolder helper, TemperatureTableItem item) {

        Spanny spanny = new Spanny();

        switch (helper.getItemViewType()) {

            case TemperatureTableItem.ONE:
                if (item != null) {
                    if (item.getLogTime() != null) {
                        helper.setText(R.id.tv_time, item.getLogTime().substring(0,item.getLogTime().length()-3));
                    }else{
                        helper.setText(R.id.tv_time, "时间");
                    }
                    if (item.getLogValue() != null) {
                        helper.setText(R.id.tv_val, item.getLogValue());
                    }
                    TextView tv_company=helper.getView(R.id.tv_company);
                    TextPaint tp = tv_company.getPaint();
                    if (item.getStats() != null) {
                        if (item.getStats().equals("0")) {
                            spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                        } else if (item.getStats().equals("1")) {
                            spanny.append("低热", new ForegroundColorSpan(color(R.color.red)));
                            tp.setFakeBoldText(true);
                        } else if (item.getStats().equals("2")) {
                            spanny.append("高热", new ForegroundColorSpan(color(R.color.red)));
                            tp.setFakeBoldText(true);
                        } else if (item.getStats().equals("3")) {
                            spanny.append("心动过缓", new ForegroundColorSpan(color(R.color.red)));
                            tp.setFakeBoldText(true);
                        } else if (item.getStats().equals("4")) {
                            spanny.append("心动过速", new ForegroundColorSpan(color(R.color.red)));
                            tp.setFakeBoldText(true);
                        }else if(item.getStats().equals("-1")){
                            spanny.append("体温过低", new ForegroundColorSpan(color(R.color.red)));
                            tp.setFakeBoldText(true);
                        }
                    }else{
                        spanny.append("状态", new ForegroundColorSpan(color(R.color.textcolor)));
                        helper.setText(R.id.tv_val,item.getDailyitemDose());
                    }
                    tv_company.setText(spanny);
                }
                break;

            case TemperatureTableItem.TWO:

                break;

            case TemperatureTableItem.THREE:
                //检测时间
                if (item.getLogTime() != null && item.getLogTime().length() > 0) {
                    helper.setText(R.id.tv_blood_time, item.getLogTime().substring(0,item.getLogTime().length()-3));
                }

                StringBuffer stringBuffer=new StringBuffer();
                stringBuffer.append(item.getLogValue()+"/");
                stringBuffer.append(item.getPaired());
                //血压低
                if (item.getPaired() != null) {
                    helper.setText(R.id.tv_val_low, stringBuffer.toString());
                }
                //级别
                TextView tv_stas = helper.getView(R.id.tv_stas);
                if (item.getStats() != null) {
                    errValbool(item.getStats(), tv_stas);
                }
                break;

            case TemperatureTableItem.FOUR:
                if (item.getLogTime() != null) {
                    helper.setText(R.id.title, item.getLogTime().substring(0,item.getLogTime().length()-3));//检测时间
                }
                if (item.getDailyitemName() != null) {
                    helper.setText(R.id.msg, item.getDailyitemName());//检测项
                }
                if (item.getLogValue()!=null) {
                    helper.setText(R.id.msgcheck, item.getLogValue() );//检测值
                }
                TextView demo=helper.getView(R.id.demo);
                TextPaint tp = demo.getPaint();
                if(item.getStats()!=null){
                    if (item.getStats().equals("0")) {
                        spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                    } else if (item.getStats().equals("1")) {
                        spanny.append("高血糖", new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                    } else if (item.getStats().equals("2")) {
                        spanny.append("危机值", new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                    }
                }else{
                    spanny.append("状态", new ForegroundColorSpan(color(R.color.textcolor)));
                }
                demo.setText(spanny);

                break;
            case TemperatureTableItem.FIVE:
                helper.setText(R.id.title,"时间");//检测时间
                helper.setText(R.id.msg, "项目");//检测时间
                StringBuffer stringBuffer1=new StringBuffer();
                if(item.getLogValue()!=null){
                    stringBuffer1.append(item.getLogValue());
                }else{
                    stringBuffer1.append("检测值");
                }
                helper.setText(R.id.msgcheck,stringBuffer1.toString());//检测时间
                helper.setText(R.id.demo,"状态");//检测时间
                break;

            case TemperatureTableItem.SIX:
                helper.setText(R.id.title, item.getLogTime().substring(0,item.getLogTime().length()-3));//检测时间
                TextView textView=helper.getView(R.id.msg);

                StringBuffer buffer=new StringBuffer();
                if(item.getMarkValues()!=null && item.getMarkValues().length()>0){
                    buffer.append(item.getMarkValues());
                }else{
                    buffer.append(item.getDailyitemName());
                }
                textView.setText(buffer.toString());//检测项

                if(item.getDailyitemName().equals("出量")){
                    helper.setText(R.id.msgcheck, item.getLogValue());//检测值
                }else{
                    helper.setText(R.id.msgcheck, item.getPaired());//检测值
                }

                TextView tvdemo=helper.getView(R.id.demo);
                TextPaint tvtp = tvdemo.getPaint();
                if(item.getStats().equals("0")) {
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                }else{
                    spanny.append("危机值", new ForegroundColorSpan(color(R.color.red)));
                    tvtp.setFakeBoldText(true);
                }
                tvdemo.setText(spanny);
                break;

            case TemperatureTableItem.SERVER:

                TextView SUMtitle=helper.getView(R.id.title);
                SUMtitle.setTextColor(color(R.color.btcolor));
                SUMtitle.setText(item.getLogTime().substring(0,item.getLogTime().length()-3));

                TextView SUMmsg=helper.getView(R.id.msg);
                SUMmsg.setText(item.getDailyitemName());
                SUMmsg.setTextColor(color(R.color.btcolor));

                ViseLog.d("检测值++++++"+item.getDailyitemName());
                TextView SUMmsgcheck=helper.getView(R.id.msgcheck);
                if(item.getDailyitemName()!=null){
                    if(item.getDailyitemName().contains("出量")){
                        BigDecimal bdcheck = new BigDecimal(item.getLogValue());
                        SUMmsgcheck.setText(bdcheck.toPlainString());
                    }else{
                        BigDecimal bdpai = new BigDecimal(item.getPaired());
                        SUMmsgcheck.setText(bdpai.toPlainString());
                    }
                }

                SUMmsgcheck.setTextColor(color(R.color.btcolor));

                TextView demoSUM=helper.getView(R.id.demo);
                TextPaint tpSUM = demoSUM.getPaint();
                if(item.getStats().equals("0")) {
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                }else{
                    spanny.append("危机值", new ForegroundColorSpan(color(R.color.red)));
                    tpSUM.setFakeBoldText(true);
                }
                demoSUM.setText(spanny);

                break;
        }
    }

    public void errValbool(String statsVal, TextView tv) {
        String stats = "";
        Spanny spanny = new Spanny();
        switch (Integer.parseInt(statsVal)) {
            case 7:
                stats = "单纯收缩期高血压";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.red)));
                break;
            case 1:
                stats = "低血压";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.red)));
                break;

            case 2:
                stats = "正常";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.btcolor)));
                break;

            case 3:
                stats = "正常高值";//1级高血压(轻度)
                spanny.append(stats, new ForegroundColorSpan(color(R.color.btcolor)));
                break;

            case 4:
                stats = "1级高血压(轻度)";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.red)));
                break;

            case 5:
                stats = "2级高血压(中度)";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.red)));
                break;

            case 6:
                stats = "3级高血压(重度)";
                spanny.append(stats, new ForegroundColorSpan(color(R.color.red)));
                break;

        }
        tv.setText(spanny);
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
